import QtQuick

Window {
    id:_win
    modality: Qt.ApplicationModal
    flags:  Qt.FramelessWindowHint|Qt.Dialog
    color: "#00000000"

    property Component comTitle
    property Component comFrame
    property Component comClient

    property var defaultBackgroundRadius:10
    property var defaultBackgroundColor:"white"
    property var defaultTitleHight:20
    property var defaultTitleBarEnableMask:XTitleBar.DISABLE_MIN | XTitleBar.DISABLE_MAX
    property var defaultTitleBarShowMask: XTitleBar.SHOW_CLOSE

    property var defaultTitleColor:"#FF26344C"

    Loader{
        anchors.fill: parent
        sourceComponent: comClient
    }

    comClient: Rectangle{
        radius: defaultBackgroundRadius
        color: defaultBackgroundColor
        Loader{
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            height: defaultTitleHight
            sourceComponent: comTitle
        }
        Loader{
            y:defaultTitleHight
            anchors.left: parent.left
            anchors.right: parent.right
            height: parent.height - defaultTitleHight
            sourceComponent: comFrame
        }
    }

    comTitle:Item{
        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            property point clickPos: "0,0"
            onPressed: {
                clickPos = Qt.point(mouse.x, mouse.y)
            }

            onPositionChanged: {
                var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
                _win.setX(_win.x + delta.x)
                _win.setY(_win.y + delta.y)
            }
        }
        XTitleBar{
            id:_titleBar
            anchors.right: parent.right
            anchors.rightMargin: 10
            y:10

            titleBarEnableMask:defaultTitleBarEnableMask
            titleBarShowMask: defaultTitleBarShowMask
            Component.onCompleted: {
            _titleBar.sigClose.connect(_win.onSigClose)
            _titleBar.sigMin.connect(_win.onSigMin)
            _titleBar.sigMax.connect(_win.onSigMax)
            }
        }

        Text {
            text: _win.title
            y:4
            anchors.horizontalCenter: parent.horizontalCenter
            width: contentWidth
            height: contentHeight
            font.pixelSize: 13
            color: defaultTitleColor
        }

    }

    comFrame:Item{

    }

    function onSigClose(){
        _win.close()
    }
    function onSigMax() {
        if(window.visibility===5){
            _win.showNormal()
        }
        else{
            _win.showFullScreen()
        }
    }
    function onSigMin(){
        _win.doMinimized()
    }
}
